{% extends "restricted/base.html" %}
{% load nm %}
{% load js %}

{% block head_resources %}
  {{block.super}}
  {% jsinclude "tables" %}
  {% jsinclude "tables,sparkline" %}
{% endblock %}

{% block head %}
{{block.super}}
<script type="text/javascript">
$(function() {
    $("#emails").tablesorter({
        textExtraction: function(node) {
            val = node.getAttribute("val");
            if (val == null)
                val = node.textContent || node.innerText;
            return val;
        },
    })

    $(".mbox_sparkline").sparkline("html", {
      type: "bar",
      barColor: "#005382",
      negBarColor: "#823000",
      chartRangeMin: -30,
      chartRangeMax: 30
    });
});
</script>
{% endblock %}

{% block content %}

<h1>Mailbox statistics</h1>

<table id="emails" class="tablesorter">
    <thead>
        <tr>
            <th>E-mail</th>
            <th>Person</th>
            <th>First mail</th>
            <th>Last mail</th>
            <th>Mail count</th>
            <th>Median</th>
            <th>Mean</th>
            <th>History</th>
        </tr>
    </thead>
    <tbody>
      {% for email, stats in emails %}
      <tr>
        <td>{{email}}</td>
        <td>{{stats.person}}</td>
        <td val="{{stats.date_first}}">{{stats.date_first_py|date:"Y-m-d"}}</td>
        <td val="{{stats.date_last}}">{{stats.date_last_py|date:"Y-m-d"}}</td>
        <td>{{stats.num_mails}}</td>
        <td val="{{stats.median}}">
          {% if stats.median_py %}
            {% if stats.median_py.days %}{{stats.median_py.days}}d {% endif %}{{stats.median_hours}}h
          {% else %}
            -
          {% endif %}
        </td>
        <td><span class="mbox_sparkline" values="{{stats.response_time|join:","}}"></span></td>
        {#"median": 585625.0, "mean_fancy": "35 days, 0:30:08", "median_fancy": "6 days, 18:40:25"#}
      </tr>
      {% endfor %}
    </tbody>
</table>

{% endblock %}
